home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / bobtest.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  6KB  |  200 lines

  1. /* bobtest.c simple bobs test program v1.0 */
  2. /****************************************************************
  3. *                                                               *
  4. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  5. * No part of this program may be reproduced, transmitted,       *
  6. * transcribed, stored in retrieval system, or translated into   *
  7. * any language or computer language, in any form or by any      *
  8. * means, electronic, mechanical, magnetic, optical, chemical,   *
  9. * manual or otherwise, without the prior written permission of  *
  10. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  11. * Los Gatos, CA 95030                                           *
  12. *                                                               *
  13. ****************************************************************/
  14. /* PROGRAM TO PUT UP A BLOCK-BOB IN A WINDOW AND BOUNCE IT AROUND A BIT */
  15.  
  16. /* Author: Rob Peck  9/10/85 */
  17.  
  18. #include <exec/types.h>
  19. #include <graphics/gfx.h>
  20. #include <graphics/rastport.h>
  21. #include <graphics/view.h>
  22. #include <exec/exec.h>
  23. #include <graphics/gels.h>
  24. #include <intuition/intuition.h>
  25.  
  26.  
  27. #define DEPTH 3
  28. long GfxBase = 0;
  29. long IntuitionBase=0;
  30.  
  31. struct Window *OpenWindow();
  32. struct InputEvent *Intuition();
  33. struct Screen *OpenScreen();
  34. struct RastPort *CDRastPort();
  35.  
  36. struct Window *w;
  37. struct Screen *screen;
  38. struct RastPort *rp;
  39. struct ViewPort *vp;
  40.  
  41. struct TextAttr TestFont = { "topaz.font", 9, 0, 0 };
  42.  
  43. struct NewScreen ns = {
  44.         0, 0,                   /* start position               */
  45.         320, 200, DEPTH,
  46.         0, 1,                   /* detail pen, block pen        */
  47.         0,                      /* viewing mode (was HIRES)     */
  48.         CUSTOMSCREEN,           /* screen type                  */
  49.         &TestFont,              /* font to use                  */
  50.         "Gels Test Program",    /* default title for screen     */
  51.         NULL                    /* pointer to additional gadgets */
  52.         };
  53.  
  54. #define WINDOWFLAGS (GIMMEZEROZERO|WINDOWDRAG|WINDOWSIZING|WINDOWDEPTH|WINDOWCLOSE)
  55.  
  56. struct NewWindow nw = {
  57.         20, 20,                 /* start position               */
  58.         220, 150,               /* width, height                */
  59.         -1, -1,                 /* detail pen, block pen        */
  60.         0,
  61.                                 /* IDCMP flags                  */
  62.         WINDOWFLAGS,    
  63.                                 /* window flags                 */
  64.         NULL,                   /* pointer to first user gadget */
  65.         NULL,                   /* pointer to user checkmark    */ 
  66.         "Big Bob",              /* window title         */ 
  67.         NULL,                   /* pointer to screen    (later) */
  68.         NULL,                   /* pointer to superbitmap       */
  69.         10,10,300,160,          /* sized window */
  70.         CUSTOMSCREEN            /* type of screen in which to open */   
  71.         };
  72.  
  73.  
  74. main()
  75. {
  76.  
  77.         GfxBase = OpenLibrary("graphics.library", 0);
  78.         if (GfxBase == NULL)
  79.         {
  80.                 printf("Unable to open graphics library\n");
  81.                 exit(1000);
  82.         }
  83.         IntuitionBase = OpenLibrary("intuition.library", 0);
  84.         if (IntuitionBase == NULL)
  85.         {
  86.                 printf("Unable to open intuition library\n");
  87.                 exit(1000);
  88.         }
  89.  
  90.         screen = OpenScreen(&ns);
  91.         nw.Screen = screen;
  92.  
  93.         w = OpenWindow(&nw);            /* open a window */
  94.         rp = w->RPort;
  95.         vp = &w->WScreen->ViewPort;
  96.  
  97.         test2();
  98.  
  99.  
  100. }
  101.  
  102.  
  103. struct VSprite s1, s2;  /* dummy sprites for gels list */
  104. struct GelsInfo gelsinfo;       /* gelsinfo to link into system rastport */
  105. struct collTable collisiontable;
  106.  
  107. struct VSprite v;
  108. struct Bob b;
  109.  
  110. SHORT i;
  111.  
  112. SHORT collmask[5 * 42];
  113. SHORT borderline[5];
  114.  
  115. SHORT savebuffer[5 * 42 * 3];
  116. SHORT dummy[ 1 * 42 * 3 ];      /* in case for some reason system needs
  117.                                  * one extra word per line to properly
  118.                                  * perform the save 
  119.                                  */
  120.  
  121. SHORT xspeed;
  122. SHORT yspeed;
  123. SHORT *images;
  124.  
  125. test2()
  126. {
  127.         SHORT *j;
  128.         gelsinfo.nextLine = NULL;
  129.         gelsinfo.lastColor = NULL;
  130.         gelsinfo.collHandler = &collisiontable;
  131.         
  132.         InitGels(&s1, &s2, &gelsinfo);
  133.         rp->GelsInfo = &gelsinfo;
  134.  
  135.         xspeed = 2;
  136.         yspeed = 4;
  137.  
  138.         v.X = 20;
  139.         v.Y = 20;
  140.         v.Flags = OVERLAY | SAVEBACK;
  141.         v.Height = 42;          /* 42 lines high */
  142.         v.Width = 5;            /* 5 words per row is 80 bits */        
  143.         v.Depth = 3;            /* 3 planes deep, will use same for
  144.                                  * its playfield */
  145.         v.MeMask = 1;
  146.         v.HitMask = 1;
  147.  
  148.         /* HERE SET VALUE OF IMAGE TO THE PROPER AREA OF THE LOADED DATA */
  149.  
  150.         images = (SHORT *)AllocMem(32000, MEMF_PUBLIC + MEMF_CLEAR);
  151.  
  152.         j = images;
  153.         for(i=0; i< 16000; i++) 
  154.                 *j++ = 0xaa3c;
  155.  
  156.         v.ImageData = (images + 20); 
  157.         v.CollMask = &collmask[0];
  158.         v.BorderLine = &borderline[0];
  159.  
  160.         InitMasks(&v);
  161.  
  162.         v.PlanePick = 0x07;     /* pick 3 planes */
  163.         v.PlaneOnOff = 0x0;     /* all zeros to others if any */
  164.  
  165.         /* ****************** now initialize the Bob variables ******* */       
  166.  
  167.         b.Flags = 0;
  168.         b.SaveBuffer = &savebuffer[0];  /* show where to save background */
  169.         b.ImageShadow = &collmask[0];   /* collision and shadow are same */
  170.         b.Before = NULL;        /* dont care about drawing order */
  171.         b.After = NULL; 
  172.         
  173.         b.BobComp = NULL;       /* not animation component */
  174.         b.DBuffer = NULL;       /* not double buffered */
  175.         
  176.         b.BobVSprite = &v;      /* link them together */
  177.         v.VSBob = &b;
  178.  
  179.         AddBob(&b, rp);
  180.         SortGList(rp);
  181.         WaitTOF();
  182.         DrawGList(rp,vp);
  183.  
  184. for(;;)
  185.         {
  186.         b.BobVSprite->Y += yspeed;
  187.         if(b.BobVSprite->Y > 100 || b.BobVSprite->Y < 10)
  188.                 yspeed = -yspeed;
  189.         b.BobVSprite->X += xspeed;
  190.         if(b.BobVSprite->X > 100 || b.BobVSprite->X < 10)
  191.                 xspeed = -xspeed;
  192.         SortGList(rp);
  193.         WaitTOF();
  194.         WaitTOF();
  195.         DrawGList(rp,vp);
  196.         }
  197. return;
  198. }       /* end of test2 */
  199.  
  200.